﻿using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService.Symbols;

/// <summary>
///     枚举成员符号声明，即声明在Enum-End Enum语法块中的类别。
/// </summary>
public class EnumMemberSymbol : AbstractTypeSymbol
{
    internal EnumMemberSymbol(EnumSymbol enumSymbol, EnumMemberSignature signature) :
        base(SymbolKinds.NamedType, TypeKinds.EnumMember)
    {
        Declaration = signature;
        ContainingSymbol = enumSymbol;
    }

    public override EnumMemberSignature Declaration { get; }

    public override EnumSymbol ContainingSymbol { get; }

    public override string Name => Declaration.Name;

    public override bool IsEnum => true;


    /// <summary>
    ///     枚举成员对应的整数值。如果语法中没有指定，将从前一个指定的值依次加一。
    ///     如果全部都未指定，将从0开始依次加一。
    /// </summary>
    public int Value => Declaration.Value;


    internal override bool TryAddMember(ISymbol member)
    {
        return false;
    }


    public override bool IsAssignableFrom(ITypeSymbol type)
    {
        return type == ValueTypeSymbol.Long || ReferenceEquals(this, type) ||
               (type.TypeKind == TypeKinds.EnumMember && ContainingSymbol == type.ContainingSymbol);
    }
}